package com.tms.springboot.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.util.StringUtil;
import com.tms.springboot.base.pojo.PdAgencyScope;
import com.tms.springboot.result.JsonResult;
import com.tms.springboot.result.ResultTool;
import com.tms.springboot.service.PdAgencyScopeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 机构业务范围表 前端控制器
 * </p>
 *
 * @author cjj
 * @since 2023-06-14
 */
@RestController
@RequestMapping("/pd-agency-scope")
public class PdAgencyScopeController {


    @Autowired
    private PdAgencyScopeService service;

    /**
     * 根据组织id查看对应的
     * @param id
     * @return
     */
    @GetMapping("/queryAreaAgencyScopeByAgencyId/{id}")
    public JsonResult queryAreaAgencyScopeByAgencyId(@PathVariable String id) {

        LambdaQueryWrapper<PdAgencyScope> lqw=new LambdaQueryWrapper<>();
        if (!StringUtil.isEmpty(id)) {
            lqw.eq(PdAgencyScope::getAgencyId,id);
        }
        PdAgencyScope one = service.getOne(lqw);
        return one !=null ? ResultTool.success(one) : ResultTool.fail();
    }

    /**
     * 添加机构作业范围
     * @param pdAgencyScope
     * @return
     */
    @RequestMapping("/addAgencyScope")
    public JsonResult addAgencyScope(@RequestBody PdAgencyScope pdAgencyScope){
        return this.service.save(pdAgencyScope) ? ResultTool.success() : ResultTool.fail();
    }

    /**
     * 修改机构范围
     * @param pdAgencyScope
     * @return
     */

    @RequestMapping("/updateAgencyScope")
    public JsonResult updateAgencyScope(@RequestBody PdAgencyScope pdAgencyScope){
        return this.service.updateById(pdAgencyScope) ? ResultTool.success() : ResultTool.fail();
    }

}
